<?php
namespace app\common\model;

class SystemMenu extends Base
{
    // protected $name = 'admin';

    public function getIconAttr($val)
    {
        if(!$val){
            return '';
        }

        return '<i class="layui-icon ' . $val . '"></i>';
    }

    public static function setIsShow($id)
    {
        $info = self::getFind(['id' => $id]);

        if($info['is_show'] == 0){
            $is_show      = 1;
            $back['flag'] = 1;
            $back['msg']  = '显示成功';
        }else{
            $is_show      = 0;
            $back['flag'] = 0;
            $back['msg']  = '隐藏成功';
        }

        $data = [
            'id'       => $id,
            'is_show'  => $is_show,
        ];
        
        self::update($data);

        if($info['pid'] == 0){
            self::update(['is_show' => $is_show], ['pid' => $id]);
        }
        return $back;
    }
}